// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SET_TSImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.IVL_TS;
import com.sunwayhorizo.health.hl7.datatypes.SET_TS;
import com.sunwayhorizo.health.hl7.datatypes.TS;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            SETCommonImpl, ANYImpl, BLImpl, CSImpl, 
//            TYPEImpl

public class SET_TSImpl extends SETCommonImpl
    implements SET_TS
{

    public static final String RCS_ID = "$Header: SET_TSImpl.java 115.20 2005/09/16 09:22:48 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: SET_TSImpl.java 115.20 2005/09/16 09:22:48 amchanda noship $", "oracle.apps.ctb.hl7.types.common");
    private static final SET_TS nullNI = new SET_TSImpl(CSImpl.valueOf("NI"));
    private static final SET_TS nullOTH = new SET_TSImpl(CSImpl.valueOf("OTH"));
    private static final SET_TS nullNINF = new SET_TSImpl(CSImpl.valueOf("NINF"));
    private static final SET_TS nullPINF = new SET_TSImpl(CSImpl.valueOf("PINF"));
    private static final SET_TS nullUNK = new SET_TSImpl(CSImpl.valueOf("UNK"));
    private static final SET_TS nullASKU = new SET_TSImpl(CSImpl.valueOf("ASKU"));
    private static final SET_TS nullNAV = new SET_TSImpl(CSImpl.valueOf("NAV"));
    private static final SET_TS nullMSK = new SET_TSImpl(CSImpl.valueOf("MSK"));
    private static final SET_TS nullNA = new SET_TSImpl(CSImpl.valueOf("NA"));
    private static final SET_TS nullNASK = new SET_TSImpl(CSImpl.valueOf("NASK"));

    public static SET_TS valueOf(Set set)
    {
        return new SET_TSImpl(set);
    }

    public static SET_TS nullSET_TS()
    {
        return new SET_TSImpl(((CS) (null)));
    }

    public SET_TSImpl(Set set)
    {
        super(set);
    }

    public SET_TSImpl(CS cs)
    {
        super(cs);
    }

    public BL contains(TS ts)
    {
        return BLImpl.valueOf(mSet.contains(ts));
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.SET_TS;
    }

    public BL contains(SET_TS set_ts)
    {
        if(isNull().isTrue())
            return BLImpl.FALSE;
        else
            return BLImpl.valueOf(mSet.containsAll(set_ts.toSet()));
    }

    public SET_TS union(SET_TS set_ts)
    {
        if(isNull().isTrue())
            if(set_ts.isNull().isTrue())
                return this;
            else
                return set_ts;
        if(set_ts.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.addAll(set_ts.toSet());
            return valueOf(hashset);
        }
    }

    public SET_TS union(TS ts)
    {
        if(ts.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.add(ts);
            return new SET_TSImpl(hashset);
        }
    }

    public SET_TS except(TS ts)
    {
        if(isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.remove(ts);
            return new SET_TSImpl(hashset);
        }
    }

    public SET_TS except(SET_TS set_ts)
    {
        if(isNull().or(set_ts.isNull()).isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            Set set = set_ts.toSet();
            hashset.removeAll(set);
            return new SET_TSImpl(hashset);
        }
    }

    public SET_TS intersection(SET_TS set_ts)
    {
        if(isNull().or(set_ts.isNull()).isTrue())
            return nullSET_TS();
        HashSet hashset = new HashSet();
        for(Iterator iterator = set_ts.toSet().iterator(); iterator.hasNext();)
        {
            TS ts = (TS)iterator.next();
            if(mSet.contains(ts))
                hashset.add(ts);
        }

        return valueOf(hashset);
    }

    public SET_TS promotion(TS ts)
    {
        HashSet hashset = new HashSet();
        hashset.add(ts);
        return valueOf(hashset);
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof SET_TS))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            SET_TS set_ts = (SET_TS)any;
            return BLImpl.valueOf(equalsSet(set_ts.toSet()));
        }
    }

    public IVL_TS hull()
    {
        throw ANYImpl.newUnsupportedException("SET<TS>", "hull");
    }

    protected boolean verifyItem(Object obj)
    {
        return (obj instanceof TS) && ((TS)obj).nonNull().isTrue();
    }

    public int hashCode()
    {
        return super.hashCode();
    }

    public static SET_TS nullSET_TS(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
